﻿function ClientAddUser() {
    OfficeIndex = document.getElementById("drpSelectOffice").selectedIndex;
    OfficeCode = document.getElementById("drpSelectOffice").options[OfficeIndex].value;

    Url = Portal.SystemWebParts.User.User.GetAddGroupNewUrl(OfficeCode).value;
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
//    PageIndex = 0;
//    Keyword=document.getElementById("txtKeyword").value;
//    value=Portal.SystemWebParts.User.User.GetHtml(Keyword,PageIndex).value;
//    if(value.indexOf("ERROR")==-1)
//    {
//        document.getElementById("divUserMain").innerHTML=value;
//    }
}

function ClientAddUserForOffice() {
    Url = Portal.SystemWebParts.User.UserForOffice.GetAddUserUrl().value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    PageIndex = 0;
    Keyword = document.getElementById("txtKeyword").value;
    value = Portal.SystemWebParts.User.UserForOffice.GetHtml(Keyword, PageIndex).value;
    if (value.indexOf("ERROR") == -1) {
        document.getElementById("divUserMain").innerHTML = value;
    }
}

function ClientSaveAddUser()
{
    LoginName=document.getElementById("txtLoginName").value;
    FullName=document.getElementById("txtFullName").value;
    Email = document.getElementById("txtEmail").value;
    Address = document.getElementById("txtAddress").value;
    Tel = document.getElementById("txtTel").value;
    Fax = document.getElementById("txtFax").value;
    Password=document.getElementById("txtPassword").value;
    ConfirmPassword = document.getElementById("txtRePassword").value;

    OfficeCode = "";
    if (document.getElementById("txtOfficeCode") != null) {
        OfficeCode = document.getElementById("txtOfficeCode").value;
    }
    else {
        OfficeIndex = document.getElementById("drpSelectOffice").selectedIndex;
        OfficeCode = document.getElementById("drpSelectOffice").options[OfficeIndex].value;
    }

    

    UserBackEndAspx = document.getElementById("txtUserBackEndAspx").value;
    retValue = Portal.SystemWebParts.User.AddUser.ServerSideCheckPassword(Password, ConfirmPassword).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }

    retValue = Portal.SystemWebParts.User.AddUser.ServerSideAddUser(LoginName, FullName, Password, Email, Address, Tel, Fax, OfficeCode, UserBackEndAspx).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue  );
    window.close();
}


function ClientSaveAddUserForOffice() {
    LoginName = document.getElementById("txtLoginName").value;
    FullName = document.getElementById("txtFullName").value;
    Email = document.getElementById("txtEmail").value;
    Password = document.getElementById("txtPassword").value;
    ConfirmPassword = document.getElementById("txtRePassword").value;
    OfficeCode = document.getElementById("txtOfficeCode").value;

    retValue = Portal.SystemWebParts.User.AddUserForOffice.ServerSideCheckPassword(Password, ConfirmPassword).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }

    retValue = Portal.SystemWebParts.User.AddUserForOffice.ServerSideAddUser(LoginName, FullName, Password, Email, OfficeCode).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}


function ClientDeleteUser(UserId)
{
    Msg=Portal.SystemWebParts.User.User.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.SystemWebParts.User.User.ServerSideDeleteUser(UserId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    PageIndex = 0;
    Keyword=document.getElementById("txtKeyword").value;
    value=Portal.SystemWebParts.User.User.GetHtml(Keyword,PageIndex).value;
    if(value.indexOf("ERROR")==-1)
    {
        document.getElementById("divUserMain").innerHTML=value;
    }
}


function ClientDeleteUserForOffice(UserId) {
    Msg = Portal.SystemWebParts.User.UserForOffice.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = Portal.SystemWebParts.User.UserForOffice.ServerSideDeleteUser(UserId).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    PageIndex = 0;
    Keyword = document.getElementById("txtKeyword").value;
    value = Portal.SystemWebParts.User.UserForOffice.GetHtml(Keyword, PageIndex).value;
    if (value.indexOf("ERROR") == -1) {
        document.getElementById("divUserMain").innerHTML = value;
    }
}

function ClientManageRole(UserId)
{
    Url=Portal.SystemWebParts.User.User.GetManageRoleUrl(UserId).value;
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
//    JumPageUser();
}

function ClientManageRoleForOffice(UserId) {
    Url = Portal.SystemWebParts.User.UserForOffice.GetManageRoleUrl(UserId).value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    JumPageUserForOffice();
}

function ShowClientUpdateUrlForm(UserId)
{
    Url=Portal.SystemWebParts.User.User.GetShowUpdateForm(UserId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //JumPageUser();
    window.open(Url, '_blank');
}


function ShowClientUpdateUrlFormForOffice(UserId) {
    Url = Portal.SystemWebParts.User.UserForOffice.GetShowUpdateForm(UserId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    JumPageUserForOffice();
} 

function ClientSaveUpdateUser(UserId)
{
    LoginName=document.getElementById("txtLoginName").value;
    FullName=document.getElementById("txtFullName").value;
    Email = document.getElementById("txtEmail").value;
    Address = document.getElementById("txtAddress").value;
    Tel = document.getElementById("txtTel").value;
    Fax = document.getElementById("txtFax").value;
    UserBackEndAspx = document.getElementById("txtUserBackEndAspx").value;
    OfficeCode = "";
    if (document.getElementById("txtOfficeCode") != null) {
        OfficeCode = document.getElementById("txtOfficeCode").value;
    }
    else {
        OfficeIndex = document.getElementById("drpSelectOffice").selectedIndex;
        OfficeCode = document.getElementById("drpSelectOffice").options[OfficeIndex].value;
    }
    AccountStatusIndex = document.getElementById("drpAccountStatus").selectedIndex;
    AccountStatus = document.getElementById("drpAccountStatus").options[AccountStatusIndex].value;

    RetValue = Portal.SystemWebParts.User.UpdateUser.ServerSideUpdateUser(UserId, LoginName, FullName, Email, Address, Tel, Fax, OfficeCode, UserBackEndAspx, AccountStatus).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ClientSaveUpdateUserForOffice(UserId) {
    LoginName = document.getElementById("txtLoginName").value;
    FullName = document.getElementById("txtFullName").value;
    Email = document.getElementById("txtEmail").value;
    OfficeCode = document.getElementById("txtOfficeCode").value;
    RetValue = Portal.SystemWebParts.User.UpdateUserForOffice.ServerSideUpdateUser(UserId, LoginName, FullName, Email, OfficeCode).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ShowClientUserItemUrlForm(UserId)
{
    Url=Portal.SystemWebParts.User.User.GetShowUserItemsForm(UserId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    window.open(Url, '_blank');
}


function ClientShowAddUserItemRootForm(UserId)
{
    Url=Portal.SystemWebParts.User.UserItems.GetAddUserItemFormUrl(UserId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //document.getElementById("divContentData").innerHTML=Portal.SystemWebParts.User.UserItems.GetHtml(UserId).value;
    window.open(Url, '_blank');
}


function JumPageUser(TabModuleId,MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript)
{
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.User.User.GetProcessingText().value;
    setTimeout("RealJumpPageUser("+MaxItems+","+ItemsPerRow+","+NoOfVisiblePage+","+CurrentPage+",'"+JumpJavaScript+"')",10);
}

function RealJumpPageUser(MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript)
{
    PageIndex = CurrentPage;
    Keyword = document.getElementById("txtKeyword").value;
    OfficeCode = "";
    if (document.getElementById("txtOfficeCode") != null) {
        OfficeCode = document.getElementById("txtOfficeCode").value;
    } else {
        OfficeIndex = document.getElementById("drpSelectOffice").selectedIndex;
        OfficeCode = document.getElementById("drpSelectOffice").options[OfficeIndex].value;
    }
    retValue = Portal.SystemWebParts.User.User.GetHtml(OfficeCode, Keyword, PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divUserMain").innerHTML=retValue;
}


function JumPageUserForOffice(TabModuleId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.User.UserForOffice.GetProcessingText().value;
    setTimeout("RealJumpPageUserForOffice(" + MaxItems + "," + ItemsPerRow + "," + NoOfVisiblePage + "," + CurrentPage + ",'" + JumpJavaScript + "')", 10);
}

function RealJumpPageUserForOffice(MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    PageIndex = CurrentPage;
    Keyword = document.getElementById("txtKeyword").value;
    retValue = Portal.SystemWebParts.User.UserForOffice.GetHtml(Keyword, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divUserMain").innerHTML = retValue;
}

function JumPageAvailableRole(UserId)
{
    document.getElementById("divProcessingAvailable").innerHTML=Portal.SystemWebParts.User.UsersInRole.GetProcessingText().value;
    setTimeout("RealJumPageAvailableRole('"+UserId+"')",10);
}

function RealJumPageAvailableRole(UserId)
{
    PageIndex=0;
    if(document.getElementById("divSelectAvailableRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectAvailableRole").selectedIndex;
    }
    Keyword=document.getElementById("txtAvailableKeyword").value;
    retValue=Portal.SystemWebParts.User.UsersInRole.ReadingAvailableRole(UserId,Keyword,PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAvailable").innerHTML="";
    document.getElementById("divAvailableRole").innerHTML=retValue;
}




function JumPageAvailableRoleForOffice(UserId) {
    document.getElementById("divProcessingAvailable").innerHTML = Portal.SystemWebParts.User.UsersInRoleForOffice.GetProcessingText().value;
    setTimeout("RealJumPageAvailableRoleForOffice('" + UserId + "')", 10);
}

function RealJumPageAvailableRoleForOffice(UserId) {
    PageIndex = 0;
    if (document.getElementById("divSelectAvailableRole") != null) {
        PageIndex = document.getElementById("divSelectAvailableRole").selectedIndex;
    }
    Keyword = document.getElementById("txtAvailableKeyword").value;
    retValue = Portal.SystemWebParts.User.UsersInRoleForOffice.ReadingAvailableRoleForOffice(UserId, Keyword, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAvailable").innerHTML = "";
    document.getElementById("divAvailableRole").innerHTML = retValue;
}



function JumPageAlreadyRole(UserId)
{
    document.getElementById("divProcessingAlready").innerHTML=Portal.SystemWebParts.User.UsersInRole.GetProcessingText().value;
    setTimeout("RealJumPageAlreadyRole('"+UserId+"')",10);
}

function RealJumPageAlreadyRole(UserId)
{
    PageIndex=0;
    if(document.getElementById("divSelectAlreadyRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectAlreadyRole").selectedIndex;
    }
    Keyword=document.getElementById("txtAlreadyKeyword").value;
    retValue=Portal.SystemWebParts.User.UsersInRole.ReadingAlreadyRole(UserId,Keyword,PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAlready").innerHTML="";
    document.getElementById("divAlreadyRole").innerHTML=retValue;
}





function JumPageAlreadyRoleForOffice(UserId) {
    document.getElementById("divProcessingAlready").innerHTML = Portal.SystemWebParts.User.UsersInRoleForOffice.GetProcessingText().value;
    setTimeout("RealJumPageAlreadyRoleForOffice('" + UserId + "')", 10);
}

function RealJumPageAlreadyRoleForOffice(UserId) {
    PageIndex = 0;
    if (document.getElementById("divSelectAlreadyRole") != null) {
        PageIndex = document.getElementById("divSelectAlreadyRole").selectedIndex;
    }
    Keyword = document.getElementById("txtAlreadyKeyword").value;
    retValue = Portal.SystemWebParts.User.UsersInRoleForOffice.ReadingAlreadyRoleForOffice(UserId, Keyword, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAlready").innerHTML = "";
    document.getElementById("divAlreadyRole").innerHTML = retValue;
}


function AssignUserToThisRole(UserId,RoleId)
{
    retValue=Portal.SystemWebParts.User.UsersInRole.ServerSideAddUserToRole(UserId,RoleId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRole(UserId);
    RealJumPageAlreadyRole(UserId);
}

function AssignUserToThisRoleForOffice(UserId, RoleId) {
    retValue = Portal.SystemWebParts.User.UsersInRoleForOffice.ServerSideAddUserToRole(UserId, RoleId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRoleForOffice(UserId);
    RealJumPageAlreadyRoleForOffice(UserId);
}

function RomoveUserFromThisRole(UserId,RoleId)
{
    if(confirm(Portal.SystemWebParts.User.UsersInRole.GetConfirmDeleteMsg().value)==false)return;
    retValue=Portal.SystemWebParts.User.UsersInRole.ServerSideRemoveUserFromRole(UserId,RoleId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRole(UserId);
    RealJumPageAlreadyRole(UserId);
}

function RomoveUserFromThisRoleForOffice(UserId, RoleId) {
    if (confirm(Portal.SystemWebParts.User.UsersInRoleForOffice.GetConfirmDeleteMsg().value) == false) return;
    retValue = Portal.SystemWebParts.User.UsersInRoleForOffice.ServerSideRemoveUserFromRole(UserId, RoleId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRoleForOffice(UserId);
    RealJumPageAlreadyRoleForOffice(UserId);
}

function ClientMakeXmlFile()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.User.User.GetProcessingText().value;
    setTimeout("RealClientMakeXmlFile()",10);
}

function RealClientMakeXmlFile()
{
    retValue=Portal.SystemWebParts.User.User.ServerSideMakeXmlFile().value;
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}

function ImportUserFromAdFunc()
{
    url=Portal.SystemWebParts.User.User.GetImportFromAdUrl().value;
    if(url.indexOf("ERROR")!=-1)
    {
        alert(url);
        return;
    }
    //window.showModalDialog(url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //JumPageUser();
    window.open(Url, '_blank');
}

function ClientExecuteImport()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.User.ImportUserFromAd.GetProcessingText().value;
    setTimeout("RealExecuteImport()",10);
}

function RealExecuteImport()
{
    retValue=Portal.SystemWebParts.User.ImportUserFromAd.ServerSideExecuteImport().value;
    document.getElementById("divProcessing").innerHTML="";
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divLog").innerHTML=retValue;
}


function ImportUserFromPlugInModules()
{
     document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.User.User.GetProcessingText().value;
     setTimeout("RealImportUserFromPlugInModules()",10);
}


function RealImportUserFromPlugInModules()
{
    retValue=Portal.SystemWebParts.User.User.ServerSideExecuteImportFromPlugInModules().value;
    document.getElementById("divProcessing").innerHTML="";
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue);
    JumPageUser();
    //document.getElementById("divLog").innerHTML=retValue;
}



function ClientDoSync()
{
    ConfirmMsg=Portal.SystemWebParts.User.SyncPermission.GetConfirmSyncMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.User.SyncPermission.GetProcessingText().value;
    setTimeout("RealClientDoSync()",10);
}

function RealClientDoSync()
{
    retValue=Portal.SystemWebParts.User.SyncPermission.ServerSideExecuteSycPermission().value;   
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}

function ClientChangePassword(UserId) {
    cMessage = Portal.SystemWebParts.User.User.GetConfirmSetPassword().value;
    if (confirm(cMessage) == false) return;
    rValue = Portal.SystemWebParts.User.User.ServerSideResetPassword(UserId).value;
    alert(rValue);
}

function ClientSyncUserWithPlugInService() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.User.User.GetProcessingText().value;
    setTimeout("RealSyncUserWithPlugInService()", 10);
}

function RealSyncUserWithPlugInService() {
    retValue = Portal.SystemWebParts.User.User.ServerSideSyncUserWithPlugInService().value;
    document.getElementById("divProcessing").innerHTML = "";
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}
